/* BEGIN - Bases d'utilisations d'un WS */
function WSTest()
{
	var xhr = new XMLHttpRequest();
	xhr.open("GET", "handlingData.php", true); // [method] [urlTarget] [true (asynchronous) or false (synchronous)]

	//Dans le cas de GET les variables sont transmises directement dans l'URL :
	xhr.open("GET", "handlingData.php?variable1=truc&variable2=bidule", true);
	xhr.send(null);
	//Pour POST, il faut spécifier les variables dans l'argument de send :
	xhr.open("POST", "handlingData.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("variable1=truc&variable2=bidule");

	//Proteger les variables
	var sVar1 = encodeURIComponent("contenu avec des espaces");

	//Gerer les étapes de la requête (avant open)
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
			alert("OK"); // C'est bon \o/
		}
	};

	//Récuperer le retour
	xhr.responseText;
	xhr.responseXML; 

	xhr.send(null);
}
/* END */

function WSTest()
{
	console.log("To send : name="+encodeURIComponent(name)+"&password="+encodeURIComponent(password)+"&mail="+encodeURIComponent(mail)+"");
	var xhr = new XMLHttpRequest();
	//xhr.open("POST", "http://tagthis.fil.univ-lille1.fr:8080/TagThis/users/create", true);
	xhr.open("GET", "http://tagthis.fil.univ-lille1.fr:8080/TagThis/users/name/gerard", true);
	//xhr.open("GET", "https://api.github.com/repos/GerardPaligot/NavigateXML/contributors", true);
	console.log("Open ok");
	//xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//xhr.send("name="+encodeURIComponent(name)+"&password="+encodeURIComponent(password)+"&mail="+encodeURIComponent(mail)+"");
	//xhr.send(null);
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
			console.log("Retour JSON : "+xhr.responseText+" OK");
			console.log("Retour XML : "+xhr.responseXML+" OK");
			//console.log(xhr);
		}
	};
	
	return true;
}

function WSCreateAccount(name,password,mail)
{
	console.log('WSCreateAccount('+name+','+password+','+mail+')');
	console.log("To send : name="+encodeURIComponent(name)+"&password="+encodeURIComponent(password)+"&mail="+encodeURIComponent(mail)+"");
	var xhr = new XMLHttpRequest();
	xhr.open("POST", "http://tagthis.fil.univ-lille1.fr:8080/TagThis/users/create", true);
	console.log("Open ok");
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("name="+encodeURIComponent(name)+"&password="+encodeURIComponent(password)+"&mail="+encodeURIComponent(mail)+"");
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
			console.log("Retour TEXT : "+xhr.responseText+" OK");
			console.log("Retour XML : "+xhr.responseXML+" OK");
			console.log("Retour JSON : "+xhr.responseJSON+" OK");
			console.log(xhr.responseJSON);
			//console.log(xhr);
		}
	};
	
	/*The standard XMLHttpRequest has no responseJSON property, just responseText and responseXML. 
	As long as bitly really responds with some JSON to your request, responseText should contain 
	the JSON code as text, so all you've got to do is to parse it:*/

	var jsonResponse = JSON.parse(req.responseText);
	/*If you prefer to use responseJSON, but want a more lightweight solution than JQuery, you might 
	want to check out my JSONHttpRequest. It works exactly like a normal XMLHttpRequest, but also 
	provides the responseJSON property. All you have to change in your code would be the first line:*/

	var req = new JSONHttpRequest();
	/*JSONHttpRequest also provides functionality to easily send JavaScript objects as JSON. More 
	details and the code can be found in my blog: http://pixelsvsbytes.com/blog/2011/12/teach-your-xmlhttprequest-some-json/.*/
	
	return true;
}

function WSUpdateAccount(name,password1,password2,mail1,mail2)
{
	if(password1!=null && password1==password2){}
	
}

function WSDeleteComment(id)
{
	console.log("WSDeleteComment("+id+")");
}

function WSGetComment(user)
{
	console.log("WSGetComment("+user+")");
	/* id_message, content_message, latitude_message, longitude_message, date_message, statut_message, id_user, btn	
	[2,"La B.U est en rénovation jusqu'en 2016",50.609370,3.142110,'2013-09-27 14:18:25',,0,1]*/
	return [	['me',"La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609772,3.136768],
				['azerrty',"11C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',48.858158,2.294660],
				['me',"11La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"11Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609772,3.136768],
				['azerrty',"22C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',48.858158,2.294660],
				['me',"22La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"22Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609772,3.136768],
				['azerrty',"22C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',48.858158,2.294660],
				['me',"33La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"33Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609772,3.136768],
				['azerrty',"33C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',48.858158,2.294660],
				['me',"44La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"44Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609772,3.136768],
				['azerrty',"44C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',50.609370,3.142110],
				['me',"55La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"55Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609370,3.142110],
				['azerrty',"55C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',50.609370,3.142110],
				['me',"66La B.U est en rénovation jusqu'en 2016",'2013-09-27 14:18:25',50.609370,3.142110],
				['truc',"66Ici c'est la salle des master 2 IAGL !",'2013-08-27 12:13:15',50.609370,3.142110],
				['azerrty',"66C tro b1 la tour FL, g u tro peur lol!",'2013-09-10 09:55:05',50.609370,3.142110]
			];
}